﻿//using System.Collections.Generic;
//using System.Data;
//using System.Linq;
//using Dapper;

//namespace FDSimpleModelGenerator.DapperAccessor
//{
//    /// <summary>
//    /// dapper辅助工具类（所有的操作，必须使用参数化语句）
//    /// </summary>
//    public class DapperUtils
//    {
//        /// <summary>
//        /// 执行参数化SQL
//        /// </summary>
//        /// <returns>受影响的行数</returns>
//        public static int Execute(string connectionString, string sql, object param = null,
//            CommandType commandType = CommandType.Text)
//        {
//            using (IDbConnection cnn = new SqlConnection(connectionString))
//            {
//                return SqlMapper.Execute(cnn, sql, param, null, null, commandType);
//            }
//        }

//        /// <summary>
//        /// 执行查询, 返回指定的T数据类型
//        /// </summary>
//        public static IList<T> Query<T>(string connectionString, string sql, object param = null,
//            CommandType commandType = CommandType.Text)
//        {
//            using (IDbConnection cnn = new SqlConnection(connectionString))
//            {
//                return SqlMapper.Query<T>(cnn, sql, param, null, true, null, commandType).ToList();
//            }
//        }

//        /// <summary>
//        /// 执行查询返回多结果集, 可依次访问 (注意，需要关闭GridReader)
//        /// </summary>
//        public static SqlMapper.GridReader QueryMultiple(string connectionString, string sql, object param = null,
//            CommandType commandType = CommandType.Text)
//        {
//            IDbConnection cnn = new SqlConnection(connectionString);
//            return SqlMapper.QueryMultiple(cnn, sql, param, null, null, commandType);
//        }

//        /// <summary>
//        /// 执行查询，返回一个动态对象列表
//        /// </summary>
//        public static IList<dynamic> Query(string connectionString, string sql, object param = null,
//            CommandType? commandType = CommandType.Text)
//        {
//            using (IDbConnection cnn = new SqlConnection(connectionString))
//            {
//                return SqlMapper.Query(cnn, sql, param, null, true, null, commandType).ToList();
//            }
//        }

//        /// <summary>
//        /// 执行查询条数
//        /// </summary>
//        /// <typeparam name="T"></typeparam>
//        /// <param name="connectionString"></param>
//        /// <param name="sql"></param>
//        /// <param name="param"></param>
//        /// <param name="commandType"></param>
//        /// <returns></returns>
//        public static T Scalar<T>(string connectionString, string sql, object param = null,
//            CommandType? commandType = CommandType.Text)
//        {
//            using (IDbConnection cnn = new SqlConnection(connectionString))
//            {
//                return SqlMapper.ExecuteScalar<T>(cnn, sql, param, null, null, commandType);
//            }
//        }
//    }
//}
